<template>
  <div class="contact-categories">
    <div class="category-tabs" role="tablist" aria-label="联系人分类">
      <button
        v-for="category in categories"
        :key="category.type"
        class="category-tab"
        :class="{ active: modelValue === category.type }"
        role="tab"
        :aria-selected="modelValue === category.type"
        :aria-label="`切换到${category.name}分类，共${category.count}个联系人`"
        @click="handleCategoryChange(category.type)"
      >
        <component :is="category.icon" :size="16" />
        <span>{{ category.name }}</span>
        <span class="category-count">({{ category.count }})</span>
      </button>
    </div>
  </div>
</template>

<script setup lang="ts">
import type { ContactCategory } from './types'

interface Props {
  modelValue: string
  categories: ContactCategory[]
}

interface Emits {
  (e: 'update:modelValue', value: string): void
  (e: 'change', value: string): void
}

defineProps<Props>()
const emit = defineEmits<Emits>()

const handleCategoryChange = (categoryType: string): void => {
  emit('update:modelValue', categoryType)
  emit('change', categoryType)
}
</script>

<style scoped>
.contact-categories {
  margin-bottom: 24px;
}

.category-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.category-tab {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border: 1px solid var(--border-color-light);
  border-radius: 20px;
  background-color: var(--background-color-secondary);
  color: var(--text-color-secondary);
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 14px;
  outline: none;
}

.category-tab:hover {
  background-color: var(--background-color-tertiary);
}

.category-tab.active {
  background-color: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.category-count {
  font-size: 12px;
  opacity: 0.8;
}
</style>
